<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fick.hibernate.model.Admin"%>
<%@ page import="com.fick.hibernate.dao.*" %>
<%@page import="com.fick.util.DES"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户管理</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px;}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12px;}

</style>
<script type="text/javascript">
		  function sa(){
		     var currPage = document.getElementById("currPage").value;
		      var patrn=/^[0-9]{1,20}$/; 
		      if(!patrn.exec(currPage)){ 
		        alert("请输入一个数字");
		       }else{
		        location="managerUser.jsp?currPage="+currPage;
		      }
		  }
		  <%if(request.getAttribute("message")!=null){%>
		   var message="<%=request.getAttribute("message").toString()%>";
		   alert(message);
		  <%request.removeAttribute("message");
		    }%>
</script>
</head>

<%
	//当前页面
	int currPage = 1;
	//总的页数
	int totalPage = 1;
	//一个页面可显示的记录数
	int pageSize = 20;
	//总共有的记录数
	int totalCount = 1;
	AdminDAO adminDao = new AdminDAO();
	List <Admin> li = new ArrayList();
	//li = adminDao.findAll();
	//得到总的记录数
	Admin admin2 = (Admin)request.getSession().getAttribute("admin");
	if(admin2.getRole().getId() == 3)
	{
		totalCount = adminDao.getTotalCount(Admin.class);
	}
	else if(admin2.getRole().getId()==5)
	{	
		totalCount = adminDao.count(Admin.class,"where role.id != 3 ");
	}else{
		totalCount = adminDao.count(Admin.class," where adminName = '"+admin2.getAdminName()+"'");
	}
	//得到总的页数
	if(totalCount%pageSize==0){
		totalPage = totalCount/pageSize;
	}else{
		totalPage = totalCount/pageSize+1;
	}
	Admin admin = new Admin();
	//判断是否是传过来页数
	if(request.getParameter("currPage") != null){
	   currPage = Integer.parseInt(request.getParameter("currPage"));
	   if(currPage<1){
	     currPage=1;
	    }
	   if(currPage >totalPage){
	     currPage = totalPage;
	   }
	} 
	//得到记录数
	li = null;
	if(admin2.getRole().getId() == 3)
	{
		li = adminDao.findAllByPage(currPage,pageSize);
	}
	else if(admin2.getRole().getId() == 5)
	{	
		li = adminDao.findPageBySql(Admin.class,currPage,pageSize,"where role.id != 3 order by userOrder");
	}else{
		li = adminDao.findByHql("from Admin where adminName = '"+admin2.getAdminName()+"' order by userOrder");
	}
%>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="30"><img src="images/tab_03.gif" width="15" height="30" /></td>
        <td width="1101" background="images/tab_05.gif"><img src="images/311.gif" width="16" height="16" />
			<span class="STYLE4">用户管理页面</span></td>
        <td width="281" background="images/tab_05.gif">
       		<span class="STYLE4"><a href="addUser.jsp">添加用户</a></span>
        </td>
        <td width="14"><img src="images/tab_07.gif" width="14" height="30" /></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9" background="images/tab_12.gif">&nbsp;</td>
        <td bgcolor="#f3ffe3">
        <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">编号</div></td>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">角色</div></td>
        <td width="20%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">用户名</div></td>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">密码</div></td>
        <td width="20%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">所属部门</div></td>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">是否能审核</div></td>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">序号</div></td>
        <td width="12%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">操作</div></td>
        </tr>
        <%
        	if(li.size()>0){
                		for(int i = 0 ; i < li.size(); i++){
                				admin = li.get(i);
                				       String ifSuper = "";
        %>
		
		<tr>
          <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
		  <%=(currPage-1)*pageSize+i%></td>
          <td width="10%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px" class="STYLE1">
		<%=admin.getRole().getRoleName()%>
		 </td>
          <td width="20%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"> <%=admin.getAdminName()%></td>
		<td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"><%=new String(DES.decrypt(admin.getAdminPass(),DES.PASSWORD_CRYPT_KEY)) %></td>
		  <td width="20%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"> <%=admin.getUnit()%></td>
        <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"><%="on".equals(admin.getIsAss())?"是":"否" %></td> 
		 <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"> <%=admin.getUserOrder()%></td> 
		 
		  <td width="12%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
		  <a href="../admin/addUser.jsp?adminId=<%=admin.getAdminId() %>">修改</a>
		  <%
		  if (admin2.getRole().getId() == 3 || admin2.getRole().getId() == 5){
		  %><a href="login.do?method=delAdmin&adminId=<%=admin.getAdminId() %>" onclick="javascript:return confirm('确定要删除吗删后将不可恢复')">删除</a>
		  <%} %></td>
        </tr>
       
	    <% }} %>
	   
      </table>
        </td>
        <td width="9" background="images/tab_16.gif">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td height="29">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="29"><img src="images/tab_20.gif" width="15" height="29" /></td>
        <td background="images/tab_21.gif">
        <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="25" align="center" valign="middle" class="STYLE1">
		  共有［<%=totalCount %>］条 当前是第［<%=currPage %>/<%=totalPage %>］页 [<a href="managerUser.jsp?currPage=1" class="page">首页</a>][<a href="managerUser.jsp?currPage=<%=currPage-1 %>" class="page">上一页</a>][<a href="managerUser.jsp?currPage=<%=currPage+1 %>" class="page">下一页</a>][<a href="managerUser.jsp?currPage=<%=totalPage %>" class="page">尾页</a>]
		  到第
            <select name="select" onChange="gopage(this)">
			<%
				for(int i = 0;i<totalPage ; i++)
				{
					out.print("<option value='managerUser.jsp?currPage="+(i+1)+"'>"+(i+1)+"</option>");
				}
			%>
			
            </select>
          页</td>
        </tr>
    </table>
        </td>
        <td width="14"><img src="images/tab_22.gif" width="14" height="29" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<script type="text/javascript">
 function gopage(selected)
 {
 	window.open(selected.value,"_self");
 }
 </script>
<script type="text/javascript">
<!--
var message = "<%=session.getAttribute("message")%>";
if(message!=null && message!="null" && message !=""){
   alert(message);
  }
//-->
</script>
<%
	session.removeAttribute("message");
%>